<?php

require_once('Interface.php');

class CodeIslands_Island_Factory_Core implements CodeIslands_Island_Factory_Interface
{
	/**
	 * Internal cache of instantiated objects.
	 *
	 * @var mixed
	 */
	static protected $_objects;
	
	private $_api_service_factory;
	
	public function setApiServiceFactory($api_service_factory)
	{
		$this->_api_service_factory = $api_service_factory;
	}
	
	public function getIsland($island_name)
	{
		// Return the island if it has already been instantiated
		if (isset(self::$_objects[$island_name]))
			return self::$_objects[$island_name];

		require_once(ISLAND_PLUGINS_PATH . "/$island_name/$island_name.php");
		$island = new $island_name($this->_api_service_factory);
		
		return self::$_objects[$island_name] = $island;
	}
}